<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>回顾Object.defineproperty方法</title>
	</head>
	<body>
		<script>
			let number = 3000;
			let person = {name:'杭州',address:'HZ'};
			console.log(person);
			Object.defineProperty(person,'age',{
				// value:number,
				// enumerable:true, // 是否可以枚举,默认为false
				// writable:true, // 是否可以被修改,默认false
				// configurable:true,//是否可以被删除,默认false
				get() {
					console.log('有人读取了age属性的值');
					return number;
				},
				set(value) {
					console.log('有人设置了age属性的值,新值为:',value);
					number = value;
				}
			});
			console.log(person);
			console.log(Object.keys(person));
			// 数据代理：通过一个对象代理另一个对象属性中的操作(读/写)
			let obj = {x:100};
			let obj2 = {y:200};
			Object.defineProperty(obj2,'x',{
				get() {
					return obj.x;
				},
				set(value) {
					obj.x = value;
				}
			});
			console.log(obj);
			obj.x = 300;
			console.log(obj2);
			obj2.x = 500;
			console.log(obj2);
		</script>
	</body>
</html>